# import subprocess
# #第一种：
# # logfile='access.log'
# # command="'tail -f ‘+logfile+' |grep 'timeout'"
# # popen=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
# # while True:
# #     line=popen.stdout.readline().strip()
# #     print (line)
#
#
# # 第二种
#
# # import time
# # file = open('access.log')
# # while 1:
# #     where = file.tell()
# #     line = file.readline()
# #     if not line:
# #         time.sleep(1)
# #         file.seek(where)
# #     else:
# #         print (line)
#
#
# # 第三种：
# # 利用python的 yield来实现一个生成器函数，
# # 然后调用这个生成器函数，这样当日志文件有变化时就打印新的行，代码如下：
#
# import time
# def follow(thefile):
#     thefile.seek(0,2)
#     while True:
#         line = thefile.readline()
#         if not line:
#             time.sleep(0.1)
#             continue
#             yield line
# if __name__ == '__main__':
#
#     logfile = open('access.log','r')
#     loglines = follow(logfile)
#     for line in loglines:
#         print (line)


#########repr() 函数,获取一个对象的字符串表示
# s = 'RUNOOB'
# print(type(repr(s)))
# print(repr(s))
# dict = {'runoob': 'runoob.com', 'google': 'google.com'};
# print(repr(dict))
# print(type(repr(dict)))

#####三引号的两个作用, 1 注释, 二 表示字符串,里面可以加注释,并且打印出来
a = 'nihao'
'''三引号注释'''
b = '''
    三英豪字符串
    #  ni
'''
# print(a,b)

#####字典
# dict = dict((['x', 1],))  #  创建字典是参数是个元组,不要忘记加逗号
# d1 = {'z':1}
# print(dict)
# print(d1)
#
# d2 = {}.fromkeys(('a','b','c'), 88)  # {'a': 88, 'b': 88, 'c': 88}
# d3 = {}.fromkeys(('a','b','c') )    # {'c': None, 'a': None, 'b': None}
# print(d3)
# print(d2)

####闭包
def counter(start=0):
    count = [start]
    def incr():
        count[0] += 4
        return count[0]
    return incr
# counter 实际是返回一个incr的对象,没有调用
cou = counter(3)
print(cou()) # 7
print(cou()) # 11










